package org.jbpm.pvm.internal.cmd;

import org.jbpm.api.NewDeployment;
import org.jbpm.api.cmd.Command;
import org.jbpm.api.cmd.Environment;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.session.DbSession;

public class UpdateDeploymentCmd implements Command<Object> {
	private static final long serialVersionUID = 1L;

	private static final Log log = Log.getLog(UpdateDeploymentCmd.class
			.getName());

	String deploymentId;
	String name;

	public UpdateDeploymentCmd(String deploymentId, String name) {
		this.deploymentId = deploymentId;
		this.name = name;
	}

	public Object execute(Environment environment) throws Exception {
		DbSession dbSession = environment.get(DbSession.class);
		NewDeployment deployment = (NewDeployment) dbSession
				.createDeploymentQuery().deploymentId(deploymentId)
				.uniqueResult();
		deployment.setName(name);
		log.debug("updating deployment " + deploymentId);
		dbSession.update(deployment);

		return null;

	}
}
